import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2023-05-06
 * Time: 21:56
 */
public class Main {
//求最大公约数
public  static int  reduce(int a,int b){
    if(b==0){
        return a;
    }

  return reduce(b,a%b);
}

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输分母");
        int a=scanner.nextInt();
        System.out.println("请输入分子");
        int b=scanner.nextInt();
        System.out.println("请输分母");
        int c=scanner.nextInt();
        System.out.println("请输入分子");
        int d=scanner.nextInt();
        if(a<0){
            a=-a;
            b=-b;
        }
        if(c<0){
            c=-c;
            d=-d;
        }
        reduce(a,b);
        a=a/reduce(a,b);
        b=b/reduce(a,b);
        reduce(c,d);
        c=c/reduce(c,d);
        d=d/reduce(c,d);

           add(a,b,c,d);
    }

    //加法
    public static void add(int a,int b,int c,int d){

        int result1=0;
        result1=b*c+d*a;//分子
        int result2=0;
        result2=a*c;//分母
        reduce(result2,result1);
        result1=result1/reduce(result2,result1);
        result2=result2/reduce(result2,result1);
        int sum=result1/result2;
        System.out.println(sum);




    }
}
